<?php
 /**
 * Redirect class definition
 *  
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MVP-PHP
 */
 
 /**
  * Encapsulates page redirection so as not to clutter other classes
  * @package MVP-PHP
  * @subpackage Base
  */    
class Redirect
{
	/**
     * Load a URL based on $mod and $page or URL and request params
	 * @param mixed $args
	 */  	
	public static function To($args)
	{
		$params = func_get_args();
		$param = $params[0];
		
		if (is_array($param)) {
			foreach ($param as $key => $value) {
				switch ($key) {
					case 'url':
					case 'params':
						$params = array_key_exists('params', $param) ? '?'. http_build_query($param['params']) : null;
						
						header("Location: {$url}{$params}");
						exit;
					case 'mod':
					case 'page':
						$mod = array_key_exists('mod', $param) ? $param['mod'] : self::$mod;
						$page = array_key_exists('page', $param) ? $param['page'] : null;
						
						header("Location: /{$mod}/{$page}");
						exit;
				}
			}
		} else {
			// try plain url
			header("Location: $param");
			exit;
		}
	}
	
	/**
     * current mod
	 * @var string
	 */  	
	public static $mod;
	
	/**
     * current page
	 * @var string
	 */  	
	public static $page;
}

?>